package engine.display.newAttack.vo
{
	import engine.data.ModelLocator;
	
	import flash.utils.flash_proxy;
	
	import toolNet.Model;

	public class AttackVo
	{
		public var attackType 	: int;
		
		public var win		: Boolean;
		
		public var sceneModel	: String;
		
		public var fightVos 	: Vector.<FightInfoVo>;
		
		public var fightPetVos	: Vector.<FightPetInfoVo>;
		
		public var boutVos		: Vector.<BoutVo>;
		
		public var configID	:String;
		
		public var leftPlayer	:String;
		
		public var rightPlayer	:String;
		
		public var leftLevel	:String;
		
		public var rightLevel	:String;
		
		public var leftModel	:String;
		
		public var rightModel	:String;
		
		public var leftClothemodel	 	:String;
		
		public var rightClothemodel	:String;
			
		public var leftTotalspeed		:String;
		
		public var rightTotalspeed		:String;
		
		public function AttackVo( attackXml : XML )
		{
			sceneModel 	= attackXml.FightInfo.@sceneModel;
			
			configID	= attackXml.@FightingGUID;
			
			attackType 	= attackXml.@FightType;
			
			leftPlayer	= attackXml.@LeftName;
			
			rightPlayer = attackXml.@RightName;
			
			leftLevel   = attackXml.@LeftLevel;
			
			rightLevel   = attackXml.@RightLevel;
			
			leftModel   = attackXml.@LeftModel;
			
			rightModel   = attackXml.@RightModel;
			
			leftClothemodel   = attackXml.@LeftClothModel;
			
			rightClothemodel   = attackXml.@RightClothModel;
			
			leftTotalspeed   = attackXml.@LeftTotalSpeed;
			
			rightTotalspeed   = attackXml.@RightTotalSpeed;
			
			fightVos	= new Vector.<FightInfoVo>();
			
			fightPetVos	= new Vector.<FightPetInfoVo>();
			
			leftClothemodel = (leftClothemodel=="0")?"1":leftClothemodel;
			rightClothemodel = (rightClothemodel=="0")?"1":rightClothemodel;
				
			boutVos		= new Vector.<BoutVo>();	
			var xml : XML;
			for each ( xml in attackXml.FightInfo.child( "Pos" ) ) 
			{
				fightVos.push( new FightInfoVo( xml ) );
			} 
			for each ( xml in attackXml.FightInfo.child( "Pet" ) ) 
			{
				fightPetVos.push( new FightPetInfoVo( xml ) );
			} 
			var boutVo : BoutVo;
			for each ( xml in attackXml.Bout ) 
			{
				boutVo = new BoutVo( xml.@count );
				boutVos.push( boutVo );
				for each( var flowXml : XML in xml.child( "Flow" ) )
				{
					boutVo.flowVos.push( new FlowVo( flowXml.@pos, flowXml.@targetpos, flowXml.@skill, 
						flowXml.@mp, flowXml.@bufferhp, flowXml.@buffermp, flowXml.@buffer, flowXml.child("Damage"), flowXml.@speak ) );
				}
				for each( var boutInfoXml : XML in xml.child( "BoutInfo" ).child( "Pos" ) )
				{
					boutVo.boutInfoVos.push( new BoutInfo( boutInfoXml.@pos, boutInfoXml.@hp, 
						boutInfoXml.@mp, boutInfoXml.@maxhp, boutInfoXml.@maxmp, boutInfoXml.@buffer ) );
				}
			}
			
			var pos:int = getMyTeam();
			
			if( pos == -1)
			{
				win = true;
			}
			else if( pos> 9)
			{
				win = attackXml.@RightResult == 2;
			}
			else if(pos <9 && pos>=0)
			{
				win = attackXml.@LeftResult == 2;
			}
		}
		
		private function getMyTeam():int
		{
			var pos : 	int = -1;
			var myName : String = ModelLocator.getInstance().scene.Role.getPlayerName();
			for each( var fightInfoVo : FightInfoVo in fightVos )
			{
				if( myName == fightInfoVo.name )
				{
					pos = fightInfoVo.pos;
					return pos;
				}
			}
			if(leftPlayer == myName)
			{
				pos = 0;
			}
			else if(rightPlayer == myName)
			{
				pos = 10;
			}
			return pos;
		}
	}
}
